/* Display.h
Copyright (c) 2008 Michael Zahniser
Please note the license terms (MIT license) at the end of this document.

Header file for the Hexie display, which displays the hex editor window
and handles user events.
*/

#ifndef __MZ_DISPLAY_H__
#define __MZ_DISPLAY_H__

#include "_sdl/Window.h"
#include "_sdl/Font.h"
#include "Editor.h"
#include "Document.h"
#include "Type.h"

#include <string>

using std::string;



class Display {
public:
	// Create a display, loading resources from the given path.
	Display();
	// The destructor quits SDL if it has been initialized.
	~Display();

	// Load the file from the given path.
	void Load(const string &filePath);
	// Run the event loop until the user quits.
	void Run();


private:
	// Create the window and load the resources.
	void Initialize();
	// Handle the given mouse event.
	void HandleMouse(const SDL_Event &event);
	
	// Redraw the entire display.
	void Draw();
	// Draw the given data with the given element type.
	void DrawData(Document::It it, Document::It end, const Type &type);
	// Draw the cursor.
	void DrawCursor();
	// Draw the status bar.
	void DrawStatusBar();
	// Draw the scroll bar.
	void DrawScrollBar();
	
	// Convert an index into a hexadecimal string.
	// Use only as many characters as are needed for this file.
	string HexLabel(size_t index) const;


private:
	// This function filters events that we don't care about.
	static int EventFilter(const SDL_Event *event);


private:
	// The window in which the data will be displayed.
	Window screen;
	// The font in which all text will be drawn.
	Font font;
	
	// The Editor handles editing of the file markup.
	Editor editor;
	
	// Track what the mouse drag is doing. If the user clicks and drags in the view,
	// the drag actions should affect the view even if the cursor, while dragging,
	// enters the scroll bar.
	enum DragArea {
		DRAG_NONE,
		DRAG_VIEW,
		DRAG_SCROLL
	} dragArea;

	// This is the number of digits needed for row labels.
	int labelDigits;

	// Colors to use for all the different objects on screen.
	map<char, Uint32> typeColor;


private:
	// Constants controlling the display dimensions.
	static const int CELL_WIDTH;
	static const int CELL_HEIGHT;
	static const int MARGIN_WIDTH;
	
	static const int STATUS_BAR_HEIGHT;
	
	static const int SCROLL_BAR_WIDTH;
	static const int SCROLL_PAD;
	static const int MIN_SCROLL_BOX;

	static const int WHEEL_SCROLL;

	static const int PAD_X;
	static const int PAD_Y;
	static const int FILL_WIDTH;
	static const int FILL_HEIGHT;

	static const int VIEW_WIDTH;
	static const int WINDOW_WIDTH;
	static const int VIEW_HEIGHT;
	static const int WINDOW_HEIGHT;
};



#endif

/* Copyright (c) 2008 Michael Zahniser

Permission is hereby granted, free of charge, to any person
obtaining a copy of this software and associated documentation
files (the "Software"), to deal in the Software without
restriction, including without limitation the rights to use,
copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following
conditions:

The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE. */
